/**
 * 增加命名空间方法<br>
 * <p>
 * 用法：$.namespace("a.b.c"); a.b.c.testFunction=function(...);
 */
$.extend($, {
	namespace : function() {
		var o = null, d = null;
		for (var i = 0, len = arguments.length; i < len; i++) {
			d = arguments[i].split(".");
			o = window[d[0]] = window[d[0]] || {};
			var left = d.slice(1);
			for (var i = 0, len = left.length; i < len; i++) {
				o = o[left[i]] = o[left[i]] || {};
			}
		}
		return o;
	},
	format : function (source, params) {
	    if (arguments.length == 1)
	        return function () {
	            var args = $.makeArray(arguments);
	            args.unshift(source);
	            return $.format.apply(this, args);
	        };
	    if (arguments.length > 2 && params.constructor != Array) {
	        params = $.makeArray(arguments).slice(1);
	    }
	    if (params.constructor != Array) {
	        params = [params];
	    }
	    $.each(params, function (i, n) {
	        source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
	    });
	    return source;
	},
	messager : {},
	SUCCESS : "1",
	ERROR : "-1"
});
$.extend($.messager, {
	alert: function(title,message){
		layer.msg(message||"提示");
	},
	show : function(opt) {
		var defaults = $.extend({}, $.fn.dialog.defaults, {
			title : "",
			width : 450,
			height : 300,
			modal : true,
			closed : true,
			maximizable : true,
			msg : ""
		}, opt);
		defaults.style.zIndex = $.fn.dialog.defaults.zIndex++;
		var win = $("<div class=\"easyui-dialog\"></div>").html(defaults.msg).appendTo("body");
		win.dialog(defaults);
		win.dialog("dialog").css(defaults.style);
		win.dialog("open");
		return win;
	}
});
$.extend(layer, {
	shortmsg : function(content, options, end){
		options = $.extend({time: 1000},options||{});
		layer.msg(content, options, end);
	},
	success : function(content, options, end){
		options = $.extend({time: 1000},options||{});
		layer.msg(content, options, end);
	},
	warning : function(content){
		layer.alert(content, {icon: 0,title:'警告'});
	},
	error : function(content){
		layer.alert(content, {icon: 2,title:'错误'});
	}
});
/**
 * 判断是否为空
 *
 * @param str
 * @returns {Boolean}
 */
function isEmpty(str) {
	if (str != "" && str != null && str.length != 0) {
		return false;
	} else {
		return true;
	}
}
$.ajaxSetup({
	cache : false,
	dataType : 'json'
});
$(document).ajaxSuccess(function(event, jqxhr, settings) {
	if (settings.url != "about:blank") {
		if (jqxhr.status == 543) {
			//layer.error("后台错误："+JSON.parse(jqxhr.responseText));
			layer.error(JSON.parse(jqxhr.responseText));
		}else if (jqxhr.responseText.indexOf('login-box') > 0) {// 新版登录界面
			layer.alert("登录超时，请重新登！",function(){
				window.top.location.reload();
			});
		}else if (jqxhr.responseText.indexOf('loginbox') > 0) {// 旧版登录界面
			layer.alert("登录超时，请重新登！",function(){
				window.top.location.reload();
			});
		}
	}
});

$(document).ajaxStop(function() {
});
$(document).ajaxError(function(event, jqxhr, settings, exception) {
	if (exception == "abort") {
		layer.error("网络中断！");
	} else if (settings.url != "about:blank") {
		if (jqxhr.status == 543) {
			//layer.error("后台错误："+JSON.parse(jqxhr.responseText));
			layer.error(JSON.parse(jqxhr.responseText));
		}else if (jqxhr.responseText.indexOf('login-box') > 0) {// 新版登录界面
			layer.alert("登录超时，请重新登！",function(){
				window.top.location.reload();
			});
		}else if (jqxhr.responseText.indexOf('loginbox') > 0) {// 旧版登录界面
			layer.alert("登录超时，请重新登！",function(){
				window.top.location.reload();
			});
		} else {
			layer.error("未捕获的异常："+jqxhr.responseText);
		}
	}
});